from json import loads

import requests
from requests import post, request, get, put, delete
# from utils.Config import logger



class Base():
    def send_get(self,url,data=None,**kwargs):
        res = get(url=url, params=data,verify=False,**kwargs).text
        # logger.info('返回内容为：' + res)
        return res

    def send_post(self,url,param_type,data=None,**kwargs):
        if param_type == "FROM":
            res = post( url=url, data=data,verify=False, **kwargs).text
        else:
            res = post( url=url, json=data,verify=False, **kwargs).text
        # logger.info('返回内容为：' + res )
        return res

    def send_put(self,url,param_type,data=None,**kwargs):
        if param_type == "FROM":
            res = put( url=url, data=data,verify=False, **kwargs).text
        else:
            res = put( url=url, json=data, verify=False, **kwargs).text
        # logger.info('返回内容为：' + res)
        return res

    def send_delete(self,url,param_type,data=None,**kwargs):
        if param_type == "FROM":
            res = delete( url=url, data=data, verify=False, **kwargs).text
        else:
            res = delete( url=url, json=data, verify=False, **kwargs).text
        # logger.info('返回内容为：' + res)
        return res

    def send_request(self,method, url, param_type=None, data=None, **kwargs):
            # 请求方式转换成大写
        method = method.upper()
            # 参数类型转换成大写
        # if param_type!=None:
        #     param_type = param_type.upper()
            # 判断是哪种请求方式
        if method=="GET":
            res = self.send_get(url,data,**kwargs)
        elif method == "POST":
                # 判断参数类型
            res = self.send_post(url,param_type,data,**kwargs)
        elif method == "PUT":
            # 判断参数类型
            res = self.send_post(url, param_type, data, **kwargs)
        elif method == "DELETE":
            # 判断参数类型
            res = self.send_post(url, param_type, data, **kwargs)
        else:
            print('ValueError')
        return res

# base=Base()
# method='Get'
# url='http://7200codeone.paas.talkweb.com.cn/uid/idaas-gateway/code-one/api/getToken?corpId=d935f4d0-39dc-403d-b1cd-b550cdda03a9&corpSecret=77c65171-6491-4ecb-b8e8-747db1c70950'
# res=base.send_request(method,url)
# print(res)

